<?php
namespace Admin\Controller;

use Common\Controller\AdminBaseController;

class TeacherController extends AdminBaseController
{

    /**
     * [教师列表信息页]
     * @method index
     * @auther 大业
     * @create 2016-10-01
     * @return [type] [description]
     */
    public function index()
    {
        $Env['title'] = '教师信息';
        //列表取表数据
        $id = '';
        $search = '';
        $style = 'admin'; //给后台管理的数据格式
        $info = D('TeacherInfo')->showInfo($id,$search,$style);
        //dump($info);
        $this->assign('env',$Env);
        $this->assign('list',$info['list']);
        $this->assign('page',$info['page']);
        $this->display('index');
        //教师列表显示的具体内容，需要后续与产品确认，并且表格多出的资料要确定如何显示
    }

    /**
     * [教师详情页]
     * @method detail
     * @auther 大业
     * @create 2016-10-01
     * @return [type] [description]
     */
    public function detail()
    {
        $Env['title'] = '教师详情';
        //列表取表数据
        $id = I('id');
        $where = 'id = '.$id;
        $info = D('TeacherInfo')->findData($where);
        //dump($info);
        $this->assign('env',$Env);
        $this->assign('list',$info);
        $this->display('detail');
    }


    /**
     * [教师信息编辑页]
     * @method edit
     * @auther 大业
     * @create 2016-10-01
     * @return [type] [description]
     */
    public function edit()
    {
        $Env['title'] = '教师信息修改';
        //列表取表数据
        $id = 1;//I('id');
        $search = '';
        $where = 'id = '.$id;
        $info = D('TeacherInfo')->findData($where);
        //dump($info);
        $this->assign('env',$Env);
        $this->assign('list',$info);
        $this->display('edit');
    }


    /**
     * [修改教师信息]
     * @method saveForm
     * @auther 大业
     * @create 2016-10-01
     * @return [type] [description]
     */
    public function saveForm()
    {
        $id = I('id');
        $data = array(
            //'tea_number'  => I('number'), #主值一般为固定值，不用修改
            'tea_name'              => I('name',''),
            'tea_sex'               => I('sex',''),
            'tea_identity_number'   => I('identity_number',''),
            'tea_mobile'            => I('mobile',''),
            'tea_phone'             => I('phone',''),
            'tea_mail'              => I('mail',''),
            'tea_weixin'            => I('weixin',''),
            'tea_native_place'      => I('native_place',''),
            'tea_working_timed'     => I('working_timed',''),
            'tea_duty'              => I('duty',''),
            'tea_certificate'       => I('certificate',''),
            'tea_introduction'      => I('introduction',''),
            'tea_join_time'         => strtotime(I('join_time','')),
            //该处需转换为时间戳strtotime('2010-03-24 08:15:42')；
            'is_working'            => I('is_working',''),
            'is_charge'             => I('is_charge',''),
        );

        //需要对表单值进行校验
        #$checkRes = checkRull();

        if($checkRes){
            $where = 'id = '.$id;
            $res = D('TeacherInfo')->editData($where,$data);
            if($res){
                echo "succ";
            }else{
                echo "error";
            }
        }
    }


    /**
     * [添加教师信息]
     * @method addForm
     * @auther 大业
     * @create 2016-10-01
     * @return [type] [description]
     */
    public function addForm()
    {
        $data = array(
            //'tea_number'  => I('number'), #主值一般为固定值，不用修改
            'tea_name'              => I('name',''),
            'tea_sex'               => I('sex',''),
            'tea_identity_number'   => I('identity_number',''),
            'tea_mobile'            => I('mobile',''),
            'tea_phone'             => I('phone',''),
            'tea_mail'              => I('mail',''),
            'tea_weixin'            => I('weixin',''),
            'tea_native_place'      => I('native_place',''),
            'tea_working_timed'     => I('working_timed',''),
            'tea_duty'              => I('duty',''),
            'tea_certificate'       => I('certificate',''),
            'tea_introduction'      => I('introduction',''),
            'tea_join_time'         => strtotime(I('join_time','')),
            'is_working'            => 1,//是否在职(0-否(离职),1-是(在职)
            'is_charge'             => I('is_charge',''),
            'add_time'              => time(),
        );

        //需要对表单值进行校验
        #$checkRes = checkRull();
        if($checkRes){
            $where = 'id = '.$id;
            $res = D('TeacherInfo')->addData($data);
            if($res){
                echo " add data succ";
            }else{
                echo " add data error";
            }
        }
    }
}
